package com.jackchen.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.jackchen.common.transform.TransformException;
import com.jackchen.common.transform.Transformer;
import com.jackchen.dao.DballDAO;
import com.jackchen.po.Dball;
import com.jackchen.po.Resource;
import com.jackchen.service.DballService;
import com.jackchen.vo.DiaryVO;

public class DballServiceImpl extends IBaseServiceImpl implements DballService {
	private static final Logger log = Logger.getLogger(DballServiceImpl.class);
	
	private DballDAO dballDAO;

	public DballDAO getDballDAO() {
		return dballDAO;
	}

	public void setDballDAO(DballDAO dballDAO) {
		this.dballDAO = dballDAO;
	}

	@Override
	public Map queryDballOnPage(String startTime, String endTime, int pageSize,
			int startRow) {
		String baseSql = " from Dball res where 1=1";
		StringBuffer hsql = new StringBuffer(baseSql);

		// 添加日期条件查询
		if(startTime != null && !"".equals(startTime.trim()) && endTime != null && !"".equals(endTime.trim())) {
			hsql.append(" AND (res.kjsj between '"+startTime+"' and '"+endTime+"' ) ");
		}else if(startTime != null && !"".equals(startTime.trim()) &&(( endTime == null) || "".equals(endTime.trim()))) {
			hsql.append(" AND (res.kjsj = '"+ startTime +"' ) ");
		}else if((startTime == null || "".equals(startTime.trim()))&& endTime != null && !"".equals(endTime.trim())) {
			hsql.append(" AND (res.kjsj = '"+ endTime +"' ) ");
		}
		
		Map logMap = dballDAO.findObjBySqlPage(hsql.toString(), pageSize, startRow);
		List logList= (List<Dball>) logMap.get("querylist");
//		List<DiaryVO> dataList = null;
//		try {
//			dataList = Transformer.pojoToVos(logList, DiaryVO.class);
//		} catch (TransformException e) {
//			// 数据转换失败
//			log.error(e.getMessage());
//			dataList = Collections.emptyList();
//		}
		logMap.put("querylist", logList);
		return logMap;

	}

	@Override
	public boolean createNewDball(Dball db) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateDball(Dball db) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Dball queryDballById(Integer dballId) {
		// TODO Auto-generated method stub
		return null;
	}
}
